package net.jgrm.common.converter;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import net.jgrm.common.util.DateUtils;
import net.jgrm.common.util.StringUtils;

import java.io.IOException;
import java.util.Date;

/**
 * JSON日期反序列化器
 * 用于处理JSON字符串到Date对象的转换
 *
 * @author service-common
 * @date 2024-09-12
 */
public class JsonDateDeserializer extends JsonDeserializer<Date> {

    @Override
    public Date deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        String dateStr = jsonParser.getText();
        if (StringUtils.isBlank(dateStr)) {
            return null;
        }
        return DateUtils.parseDate(dateStr.trim());
    }
}